package  com.globagames.strategicgames.business
{	
	import com.globagames.strategicgames.model.Player;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;


	public class PlayerDelegate
	{
		private var service:RemoteObject;
		
		public function PlayerDelegate( responder : IResponder )
		{		
			this.responder = responder;			
			service = new RemoteObject();			
			service.destination = "loginService";						
		}
		
		public function doCreate( player: Player) : void
		{								
			var call : Object = this.service.createPlayer(player);
			call.addResponder( responder );
		}
		public function doDisconnectPlayer( player: Player) : void
		{								
			var call : Object = this.service.disconnectPlayer(player.playerId);
			call.addResponder( responder );
		}
		public function doFind( player: Player) : void
		{			
			trace("doFind "+player.name);					
			var call : Object = this.service.connectPlayer(player);
			call.addResponder( responder );
		}
		public function doTouch( player: Player) : void
		{								
			var call : Object = this.service.touchPlayer(player.playerId);
			call.addResponder( responder );
		}
		
		public function doFindConnectedPlayers(player: Player) : void
		{								
			var call : Object = this.service.findConnectedPlayers(player.playerId);
			call.addResponder( responder );
		}
		private function resultHandler(event:ResultEvent):void
		{			
			this.responder.result(event);
		}
		
		private function faultHandler(event:FaultEvent):void
		{
			trace(event.fault.rootCause.message, event.fault.faultCode);
		}
									
		private var responder : IResponder;

	}

}